package com.pe1n.yangtaopai.page.detail.presenter;

import android.util.Log;

import com.pe1n.yangtaopai.bean.DetailBean;
import com.pe1n.yangtaopai.bean.InnerTypeBean;
import com.pe1n.yangtaopai.page.detail.modle.IModle;
import com.pe1n.yangtaopai.page.detail.modle.ModleImpl;
import com.pe1n.yangtaopai.page.detail.view.interfacese.IView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Pe1n on 2016/11/24.
 */

public class PresenterImpl implements IPresenter {

    private IModle mModle;
    private IView mView;

    public PresenterImpl(IView mView) {
        this.mView = mView;
        this.mModle = new ModleImpl();
    }

    @Override
    public void loadDetailBeanData(String url) {

        mModle.getDetailBean(url)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<DetailBean>() {
                    @Override
                    public void onCompleted() {
                        mView.hideProgress();
                    }

                    @Override
                    public void onError(Throwable e) {
                        StackTraceElement[] stackTrace = e.getStackTrace();
                        for (int i = 0; i < stackTrace.length; i++) {
                            Log.e("TAG", "onError: "+stackTrace[i] );
                        }

                    }

                    @Override
                    public void onNext(DetailBean detailBean) {
                        mView.loadDetailBeanData(detailBean);
                    }
                });

    }

}
